<template>
  <div class="search-container">
    <h1>域名解析查询</h1>
    <el-form :model="queryForm">
      <el-form-item>
        <el-input
          v-model="queryForm.domain"
          placeholder="输入域名/网址一键查询"
        />
      </el-form-item>
      <el-button
        class="w-full mt-4"
        size="default"
        type="primary"
        :loading="loading"
        @click="onQuery()"
      >查询</el-button>
    </el-form>
    <el-divider />
    <div v-if="resultVisiable" class="result-container">
      <h3>域名 # {{ queryForm.domain }} # 的解析结果</h3>
      <el-row v-for="(row, index) in tableData" :key="index">
        <el-divider />
        <el-row-item>
          <router-link :to="'/search/host/'+row">
            {{ row }}
          </router-link>
        </el-row-item>
      </el-row>
    </div>
  </div>
</template>

<script>
import { searchDns } from '@/api/search/index'

export default {
  name: 'SearchDns',
  data: function() {
    return {
      loading: false,
      resultVisiable: false,
      tableData: [],
      queryForm: {
        'domain': 'sina.com'
      },
      mapInstance: false
    }
  },
  methods: {
    onQuery: function() {
      this.loading = true
      this.resultVisiable = false
      searchDns(this.queryForm.domain).then(resp => {
        this.tableData = resp.data
        this.resultVisiable = true
        this.loading = false
      })
    }
  }
}

</script>

<style scoped>
h1,
h3 {
  margin-top: 20px;
  margin-bottom: 10px;
  text-align: center;
}
.search-container{
  margin:30px;
}
.result-container {
  padding: 5px 20px 10px;
  background-color: white;
}
</style>
